<template>
  <div class="list-container">
    <vab-query-form>
      <!-- <vab-query-form-left-panel :span="12">
        <el-button icon="el-icon-plus" type="primary" @click="handleEdit">
          添加
        </el-button> -->
      <!-- <el-button icon="el-icon-delete" type="danger" @click="handleDelete">
          删除
        </el-button> -->
      <!-- </vab-query-form-left-panel> -->
      <vab-query-form-left-panel :span="12">
        <el-form
          ref="form"
          :model="queryForm"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item>
            <el-input
              v-model.trim="queryForm.phone"
              placeholder="手机号码"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button
              icon="el-icon-search"
              type="primary"
              native-type="submit"
              @click="handleQuery"
            >
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-left-panel>
    </vab-query-form>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
    >
      <el-table-column
        show-overflow-tooltip
        prop="userName"
        label="真实姓名"
        width="100"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="手机号码"
        prop="phone"
        width="120"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="地产名称"
        prop="businessEstateName"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="项目名称"
        prop="projectName"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="审核状态">
        <template #default="{ row }">
          <el-tag
            size="small"
            :type="
              row.status == 2
                ? 'success'
                : row.status == 3
                ? 'danger'
                : row.status == 1
                ? 'info'
                : 'warning'
            "
          >
            {{ getValue(row.status) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="操作" width="300">
        <template #default="{ row }">
          <el-button type="primary" @click="handleEdit(row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <develop-form ref="edit" @fetch-data="fetchData"></develop-form>
    <check-developer ref="check" @fetch-data="fetchData"></check-developer>
    <!-- <el-pagination
      :background="background"
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination> -->
  </div>
</template>
<script>
  import { getDevelopList } from '@/api/user'

  import DevelopForm from './components/DevelopForm.vue'
  import CheckDeveloper from './components/CheckDeveloper.vue'
  export default {
    name: 'List',
    components: { DevelopForm, CheckDeveloper },
    data() {
      return {
        imgShow: true,
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        selectRows: '',
        elementLoadingText: '正在加载...',
        queryForm: {
          // endTime: 'string',
          phone: '',
          // startTime: 'string',
          // status: 0,
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    mounted() {},
    methods: {
      getValue(value) {
        switch (value) {
          case 1:
            return '未审核'
          case 2:
            return '已通过'
          case 3:
            return '未通过'
        }
      },
      handleEdit(row) {
        if (row) {
          this.$refs['check'].showEdit(row)
        } else {
          this.$refs['check'].showEdit()
        }
      },
      handleDelete(row) {
        if (row.userId) {
          this.$baseConfirm('你确定要删除当前项吗', null, async () => {
            //TODO:删除操作
            // const { msg } = await doDelete({ ids: row.id })
            this.$baseMessage('删除成功！', 'success')
            this.fetchData()
          })
        } else {
          return false
        }
      },

      // handleCurrentChange(val) {
      //   this.queryForm.pageNum = val
      //   this.fetchData()
      // },
      handleQuery() {
        // this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        console.log(this.queryForm)
        const { data } = await getDevelopList(this.queryForm)
        const { body } = data
        this.list = body
        // this.total = body.totalSize
        this.$baseNotify('开发商数据获取完毕！', '成功', 'success', 'top-right')
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
    },
  }
</script>
